package com.lazily.list_;


import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author:  GZQ
 * @date:  2025/4/19 17:57
 * @description: List的三种遍历方式
 * @version: 1.0
 */

public class ListFor {
	// 程序入口
	@SuppressWarnings({"all"})
	public static void main(String[] args) {

		// List 接口的实现子类 Vector LinkedList
		// List list = new ArrayList();
		// List list = new Vector();
		List list = new LinkedList();

		list.add("jack");
		list.add("tom");
		list.add("北京烤鸭");

		// 遍历
		// 1. 迭代器
		Iterator iterator = list.iterator();
		while (iterator.hasNext()) {
			Object obj = iterator.next();
			System.out.println(obj);
		}

		System.out.println("======增强for========");
		// 2. 增强for
		for (Object o : list) {
			System.out.println(o);
		}

		System.out.println("=====普通for======");
		// 3. 使用普通for
		for (int i = 0; i < list.size(); i++) {
			System.out.println(list.get(i));
		}
	}
}
